<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The SNMP class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.snmpwalkoid.html">« snmpwalkoid</a></li>
      <li style="float: right;"><a href="snmp.close.html">SNMP::close »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.snmp.html">SNMP</a></li>
    <li>The SNMP class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.snmp" class="reference">
 <h1 class="title">The SNMP class</h1>
 
 
 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p>
 

  <div class="section" id="snmp.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    Represents <abbr title="Simple Network Management Protocol">SNMP</abbr> session.
   </p>
  </div>

 
  <div class="section" id="snmp.synopsis">
   <h2 class="title">类摘要</h2>
 

   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">SNMP</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">readonly</span>
     <span class="type">array</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.info">$<var class="varname">info</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span>
      <var class="varname"><a href="class.snmp.html#snmp.props.max-oids">$<var class="varname">max_oids</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.valueretrieval">$<var class="varname">valueretrieval</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">bool</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.quick-print">$<var class="varname">quick_print</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">bool</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.enum-print">$<var class="varname">enum_print</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.oid-output-format">$<var class="varname">oid_output_format</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">bool</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.oid-increasing-check">$<var class="varname">oid_increasing_check</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname"><a href="class.snmp.html#snmp.props.exceptions-enabled">$<var class="varname">exceptions_enabled</var></a></var>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="snmp.construct.html" class="methodname">__construct</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$version</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$hostname</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$community</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$retries</code><span class="initializer"> = -1</span></span><br>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.close.html" class="methodname">close</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.get.html" class="methodname">get</a></span>(<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$objectId</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$preserveKeys</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.geterrno.html" class="methodname">getErrno</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.geterror.html" class="methodname">getError</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.getnext.html" class="methodname">getnext</a></span>(<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$objectId</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.set.html" class="methodname">set</a></span>(<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$objectId</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$type</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.setsecurity.html" class="methodname">setSecurity</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$securityLevel</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$authProtocol</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$authPassphrase</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$privacyProtocol</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$privacyPassphrase</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$contextName</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$contextEngineId</code><span class="initializer"> = &quot;&quot;</span></span><br>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="snmp.walk.html" class="methodname">walk</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$objectId</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$suffixAsKey</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$maxRepetitions</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$nonRepeaters</code><span class="initializer"> = -1</span></span><br>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 常量 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-noerror"><var class="varname">ERRNO_NOERROR</var></a></var><span class="initializer"> = 0</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-generic"><var class="varname">ERRNO_GENERIC</var></a></var><span class="initializer"> = 2</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-timeout"><var class="varname">ERRNO_TIMEOUT</var></a></var><span class="initializer"> = 4</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-error-in-reply"><var class="varname">ERRNO_ERROR_IN_REPLY</var></a></var><span class="initializer"> = 8</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-oid-not-increasing"><var class="varname">ERRNO_OID_NOT_INCREASING</var></a></var><span class="initializer"> = 16</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-oid-parsing-error"><var class="varname">ERRNO_OID_PARSING_ERROR</var></a></var><span class="initializer"> = 32</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-multiple-set-queries"><var class="varname">ERRNO_MULTIPLE_SET_QUERIES</var></a></var><span class="initializer"> = 64</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.errno-multiple-set-queries"><var class="varname">ERRNO_ANY</var></a></var><span class="initializer"> = 126</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.version-1"><var class="varname">VERSION_1</var></a></var><span class="initializer"> = 0</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.version-2c"><var class="varname">VERSION_2C</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.version-2c"><var class="varname">VERSION_2c</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.snmp.html#snmp.class.constants.version-3"><var class="varname">VERSION_3</var></a></var><span class="initializer"> = 3</span>;</div>

   }</div>
  </div>


  <div class="section" id="snmp.props">
   <h2 class="title">属性</h2>
   <dl>
    
     <dt id="snmp.props.max-oids"><var class="varname">max_oids</var></dt>

     <dd>

      <p class="para">Maximum OID per GET/SET/GETBULK request</p>
     </dd>

    
    
     <dt id="snmp.props.valueretrieval"><var class="varname">valueretrieval</var></dt>

     <dd>

      <p class="para">Controls the method how the SNMP values will be returned</p>
      <table class="doctable table">
       
       
        <tbody class="tbody">
         <tr><td><strong><code>SNMP_VALUE_LIBRARY</code></strong></td><td>The return values will be as returned by the Net-SNMP library.</td></tr>

         <tr><td><strong><code>SNMP_VALUE_PLAIN</code></strong></td><td>The return values will be the plain value without the SNMP type information.</td></tr>

         <tr>
          <td><strong><code>SNMP_VALUE_OBJECT</code></strong></td><td>
           The return values will be objects with the properties &quot;value&quot; and &quot;type&quot;, where the latter
           is one of the SNMP_OCTET_STR, SNMP_COUNTER etc. constants. The
           way &quot;value&quot; is returned is based on which one of <strong><code>SNMP_VALUE_LIBRARY</code></strong>,
           <strong><code>SNMP_VALUE_PLAIN</code></strong> is set
          </td>
         </tr>

        </tbody>
       
      </table>


     </dd>

    
    
     <dt id="snmp.props.quick-print"><var class="varname">quick_print</var></dt>

     <dd>

      <p class="para">Value of <code class="parameter">quick_print</code> within the NET-<abbr title="Simple Network Management Protocol">SNMP</abbr> library</p>
      <p class="para">
       Sets the value of <code class="parameter">quick_print</code> within the NET-<abbr title="Simple Network Management Protocol">SNMP</abbr> library.  When this
       is set (1), the <abbr title="Simple Network Management Protocol">SNMP</abbr> library will return &#039;quick printed&#039; values.  This
       means that just the value will be printed.  When <code class="parameter">quick_print</code> is not
       enabled (default) the NET-<abbr title="Simple Network Management Protocol">SNMP</abbr> library prints extra information
       including the type of the value (i.e. IpAddress or OID).  Additionally,
       if quick_print is not enabled, the library prints additional hex values
       for all strings of three characters or less.
      </p>
     </dd>

    
    
     <dt id="snmp.props.enum-print"><var class="varname">enum_print</var></dt>

     <dd>

      <p class="para">Controls the way enum values are printed</p>
      <p class="para">
       Parameter toggles if walk/get etc. should automatically lookup enum values
       in the MIB and return them together with their human readable string.
      </p>
     </dd>

    
    
     <dt id="snmp.props.oid-output-format"><var class="varname">oid_output_format</var></dt>

     <dd>

      <p class="para">Controls OID output format</p>
      <table class="doctable table">
       <caption><strong>OID .1.3.6.1.2.1.1.3.0 representation for various
       <var class="varname">oid_output_format</var> values</strong></caption>
       
        <tbody class="tbody">
         <tr><td><strong><code>SNMP_OID_OUTPUT_FULL</code></strong></td><td>.iso.org.dod.internet.mgmt.mib-2.system.sysUpTime.sysUpTimeInstance</td></tr>

         <tr><td><strong><code>SNMP_OID_OUTPUT_NUMERIC</code></strong></td><td>.1.3.6.1.2.1.1.3.0</td> </tr>

         <tr><td><strong><code>SNMP_OID_OUTPUT_MODULE</code></strong></td><td>DISMAN-EVENT-MIB::sysUpTimeInstance</td></tr>

         <tr><td><strong><code>SNMP_OID_OUTPUT_SUFFIX</code></strong></td><td>sysUpTimeInstance</td></tr>

         <tr><td><strong><code>SNMP_OID_OUTPUT_UCD</code></strong></td><td>system.sysUpTime.sysUpTimeInstance</td></tr>

         <tr><td><strong><code>SNMP_OID_OUTPUT_NONE</code></strong></td><td>Undefined</td></tr>

        </tbody>
       
      </table>

     </dd>

    
    
     <dt id="snmp.props.oid-increasing-check"><var class="varname">oid_increasing_check</var></dt>

     <dd>

      <p class="para">Controls disabling check for increasing OID while walking OID tree</p>
      <p class="para">
       Some <abbr title="Simple Network Management Protocol">SNMP</abbr> agents are known for returning OIDs out
       of order but can complete the walk anyway. Other agents return OIDs
       that are out of order and can cause <span class="methodname"><a href="snmp.walk.html" class="methodname">SNMP::walk()</a></span>
       to loop indefinitely until memory limit will be reached.
       PHP SNMP library by default performs OID increasing check and stops
       walking on OID tree when it detects possible loop with issuing warning
       about non-increasing OID faced.
       Set <var class="varname">oid_increasing_check</var> to <strong><code>false</code></strong> to disable this
       check.
      </p>
     </dd>

    
    
     <dt id="snmp.props.exceptions-enabled"><var class="varname">exceptions_enabled</var></dt>

     <dd>

      <p class="para">
       Controls which failures will raise SNMPException instead of
       warning. Use bitwise OR&#039;ed <strong><code>SNMP::ERRNO_*</code></strong> constants.
       By default all SNMP exceptions are disabled.
      </p>
     </dd>

    
    
     <dt id="snmp.props.info"><var class="varname">info</var></dt>

     <dd>

      <p class="para">Read-only property with remote agent configuration: hostname,
      port, default timeout, default retries count</p>
     </dd>

    
   </dl>

  </div>


  
  <div class="section" id="snmp.class.constants">
   <h2 class="title">预定义常量</h2>
   <div class="section" id="snmp.class.constants.error-types">
    <h2 class="title"><abbr title="Simple Network Management Protocol">SNMP</abbr> Error Types</h2>
    <dl>

     
      <dt id="snmp.class.constants.errno-noerror"><strong><code>SNMP::ERRNO_NOERROR</code></strong></dt>

      <dd>

       <p class="para">No <abbr title="Simple Network Management Protocol">SNMP</abbr>-specific error occurred.</p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-generic"><strong><code>SNMP::ERRNO_GENERIC</code></strong></dt>

      <dd>

       <p class="para">A generic <abbr title="Simple Network Management Protocol">SNMP</abbr> error occurred.</p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-timeout"><strong><code>SNMP::ERRNO_TIMEOUT</code></strong></dt>

      <dd>

       <p class="para">Request to <abbr title="Simple Network Management Protocol">SNMP</abbr> agent timed out.</p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-error-in-reply"><strong><code>SNMP::ERRNO_ERROR_IN_REPLY</code></strong></dt>

      <dd>

       <p class="para"><abbr title="Simple Network Management Protocol">SNMP</abbr> agent returned an error in reply.</p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-oid-not-increasing"><strong><code>SNMP::ERRNO_OID_NOT_INCREASING</code></strong></dt>

      <dd>

       <p class="para">
        <abbr title="Simple Network Management Protocol">SNMP</abbr> agent faced OID cycling reporning
        non-increasing OID while executing (BULK)WALK command.
        This indicates bogus remote <abbr title="Simple Network Management Protocol">SNMP</abbr> agent.
       </p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-oid-parsing-error"><strong><code>SNMP::ERRNO_OID_PARSING_ERROR</code></strong></dt>

      <dd>

       <p class="para">
        Library failed while parsing OID (and/or type for SET command).
        No queries has been made.
       </p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-multiple-set-queries"><strong><code>SNMP::ERRNO_MULTIPLE_SET_QUERIES</code></strong></dt>

      <dd>

       <p class="para">
        Library will use multiple queries for SET operation requested.
        That means that operation will be performed in a non-transaction manner 
        and second or subsequent chunks may fail if a type or value failure
        will be faced.
       </p>
      </dd>

     

     
      <dt id="snmp.class.constants.errno-any"><strong><code>SNMP::ERRNO_ANY</code></strong></dt>

      <dd>

       <p class="para">
 All SNMP::ERRNO_* codes bitwise OR&#039;ed.
       </p>
      </dd>

     

    </dl>

   </div>
   <div class="section" id="snmp.class.constants.protocols">
    <h2 class="title"><abbr title="Simple Network Management Protocol">SNMP</abbr> Protocol Versions</h2>
    <dl>

     
      <dt id="snmp.class.constants.version-1"><strong><code>SNMP::VERSION_1</code></strong></dt>

      <dd>

       <p class="para"/>
      </dd>

     

     
      <dt id="snmp.class.constants.version-2c"><strong><code>SNMP::VERSION_2C</code></strong>, <strong><code>SNMP::VERSION_2c</code></strong></dt>

      <dd>

       <p class="para"/>
      </dd>

     

     
      <dt id="snmp.class.constants.version-3"><strong><code>SNMP::VERSION_3</code></strong></dt>

      <dd>

       <p class="para"/>
      </dd>

     

    </dl>

   </div>
  </div>
  

 
 </div>
 
 

















































 
<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="snmp.close.html">SNMP::close</a> — Close SNMP session</li><li><a href="snmp.construct.html">SNMP::__construct</a> — Creates SNMP instance representing session to remote SNMP agent</li><li><a href="snmp.get.html">SNMP::get</a> — Fetch an SNMP object</li><li><a href="snmp.geterrno.html">SNMP::getErrno</a> — Get last error code</li><li><a href="snmp.geterror.html">SNMP::getError</a> — Get last error message</li><li><a href="snmp.getnext.html">SNMP::getnext</a> — Fetch an SNMP object which
  follows the given object id</li><li><a href="snmp.set.html">SNMP::set</a> — Set the value of an SNMP object</li><li><a href="snmp.setsecurity.html">SNMP::setSecurity</a> — Configures security-related SNMPv3 session parameters</li><li><a href="snmp.walk.html">SNMP::walk</a> — Fetch SNMP object subtree</li></ul>
</div>
</div></div></body></html>